package com.df.excel_export;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelReader;
import com.alibaba.excel.read.metadata.ReadSheet;
import com.df.excel_export.simple_export.SimpleHTableReaderListener;
import freemarker.template.Configuration;

import java.io.*;
import java.util.List;

public class SimpleExport {
    public static Configuration configuration = new Configuration(Configuration.getVersion());
    public static void main(String[] args) throws IOException {

        //加载插件

        // 第二步：设置模板文件所在的路径。
        String ftlPath = System.getProperty("user.dir") + File.separator + "data"+File.separator+"simple_export_templates";
        configuration.setDirectoryForTemplateLoading(new File(ftlPath));
        // 第三步：设置模板文件使用的字符集。一般就是utf-8.
        configuration.setDefaultEncoding("utf-8");

        String fileName = "D:\\My\\cocos-demo\\doc\\configs\\skill.xlsx";
        String dataFilePath = "D:\\My\\cocos-demo\\assets\\tableResources";
        String codeFilePath = "D:\\My\\cocos-demo\\assets\\Scripts\\game\\data\\static";
        //解析表头
        ExcelReader reader = EasyExcel.read(fileName).build();
        List<ReadSheet> readSheets = reader.excelExecutor().sheetList();
        for (ReadSheet readSheet : readSheets) {
            try {
                String sheetName = readSheet.getSheetName();
                readSheet.setHeadRowNumber(0);
                //包含前缀和后缀为数据表
                if (sheetName.startsWith("t_")) {
                    readSheet.getCustomReadListenerList().add(new SimpleHTableReaderListener(dataFilePath,codeFilePath));
                    reader.read(readSheet);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    private static void parserFileHeaders() {

    }


}
